package com.yangguang.huahui.ui.fragments;

import android.os.Bundle;

import com.yangguang.huahui.mvp.presenter.BasePresenter;
import com.yangguang.huahui.utils.LogUtil;


/**
 * Author: Othershe
 * Time: 2016/8/12 12:19
 */
public abstract class BaseMvpFragment<V, P extends BasePresenter<V>> extends BaseFragment {
    protected static final String SUB_TYPE = "subtype";

    protected P mPresenter;

    protected abstract P initPresenter();

    protected abstract void fetchData();

    protected boolean mIsViewInitiated;
    protected boolean mIsVisibleToUser;
    protected boolean mIsDataInitiated;

//    @Override
//    public void setUserVisibleHint(boolean isVisibleToUser) {
//        super.setUserVisibleHint(isVisibleToUser);
//        mIsVisibleToUser = isVisibleToUser;
//        fetchData();
////        initFetchData();
//    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mPresenter = initPresenter();
        mPresenter.attach((V) this);

//        mIsViewInitiated = true;
//        initFetchData();
        fetchData();
    }

//    protected void initFetchData() {
//        if (mIsVisibleToUser && mIsViewInitiated && !mIsDataInitiated) {
//            fetchData();
//            mIsDataInitiated = true;
//        }
//    }

    @Override
    public void onDestroy() {
        mPresenter.detach();
        super.onDestroy();
    }
}
